
using QdbUnit;
using QdbUnit.Extensions;
using QdbUnit.Extensions.Fixtures;
using Qdb.Internal;
using Qdb.Internal.References;

namespace Qdb.Tests.Common.Internal
{
	public class TransactionTestCase : AbstractQdbTestCase, IOptOutMultiSession
	{
		private const int TestId = 5;

		public virtual void TestRemoveReferenceSystemOnClose()
		{
			LocalObjectContainer container = (LocalObjectContainer)Db();
			IReferenceSystem referenceSystem = container.CreateReferenceSystem();
			Transaction transaction = container.NewTransaction(container.SystemTransaction(), 
				referenceSystem);
			referenceSystem.AddNewReference(new ObjectReference(TestId));
			referenceSystem.AddNewReference(new ObjectReference(TestId + 1));
			container.ReferenceSystemRegistry().RemoveId(TestId);
			Assert.IsNull(referenceSystem.ReferenceForId(TestId));
			transaction.Close(false);
			container.ReferenceSystemRegistry().RemoveId(TestId + 1);
			Assert.IsNotNull(referenceSystem.ReferenceForId(TestId + 1));
		}
	}
}
